﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace comm
{
    public partial class Video : Form
    {
        private CHCNetSDK.REALDATACALLBACK m_fRealData = null;
        //private PlayCtrl.DISPLAYCBFUN m_fDisplayFun = null;
        private CHCNetSDK.MSGCallBack m_falarmData = null;
        public CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo;
        public Int32 m_lUserID = -1;
        private bool m_bInitSDK = false;
        private Int32 m_lRealHandle = -1;
        private Int32 m_lPort = -1;
        private bool m_bJpegCapture = false;
        private Int32 m_iPreviewType = 0;
        private bool m_bGuard = false;
        private bool m_bOpenSound = false;
        private Int32 m_lFortifyHandle = -1;

        public Video()
        {
            InitializeComponent();

            m_bInitSDK = CHCNetSDK.NET_DVR_Init();
            if (m_bInitSDK == false)
            {
                MessageBox.Show("NET_DVR_Init error!");
                return;
            }
            else
            {
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "" || textBox2.Text == "" || textBox5.Text == "" || textBox6.Text == "")
            {
                MessageBox.Show("请输入参数");
                return;
            }
            string DVRIPAddress = textBox1.Text;
            Int16 DVRPortNumber = Int16.Parse(textBox6.Text);
            string DVRUserName = textBox2.Text;
            string DVRPassword = textBox5.Text;
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref m_struDeviceInfo);
            if (m_lUserID == -1)
            {
                MessageBox.Show("login error!");
                return;
            }
            else
            {
                MessageBox.Show("Login Success!");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_ClickKey(m_lUserID, Convert.ToInt32(this.textBox3.Text.Trim()));
            Thread.Sleep(400);
            if (this.textBox4.Text.Trim() != "")
            {
                CHCNetSDK.NET_DVR_ClickKey(m_lUserID, Convert.ToInt32(this.textBox4.Text.Trim()));
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_ClickKey(m_lUserID, 25);
        }

        private void button4_Click(object sender, EventArgs e)
        {
           // int aport = Convert.ToInt32(this.textBox7.Text.Trim());
            CHCNetSDK.NET_DVR_SetAlarmOut(m_lUserID, 0x0000, 1);
        }

        private void button5_Click(object sender, EventArgs e)
        {
           // int aport = Convert.ToInt32(this.textBox7.Text.Trim());
            CHCNetSDK.NET_DVR_SetAlarmOut(m_lUserID, 0x0001, 0);

        }
    }
}
